package com.xemxoso;

import android.app.Fragment;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.xemxoso.R;
import com.xemxoso.jsouplocal.JsoupLocal;
import com.xemxoso.model.KetQuaXoSoMienBac;

public class FragmentMienBac extends Fragment {
	

	private TextView txtMien;
	private TextView txtSo1;
	private TextView txtGiaiNhatSo1;
	private TextView txtGiaiNhiSo1;
	private TextView txtGiaiNhiSo2;
	private TextView txtGiaiBaSo1;
	private TextView txtGiaiBaSo2;
	private TextView txtGiaiBaSo3;
	private TextView txtGiaiBaSo4;
	private TextView txtGiaiBaSo5;
	private TextView txtGiaiBaSo6;
	private TextView txtGiaiBonSo1;
	private TextView txtGiaiBonSo2;
	private TextView txtGiaiBonSo3;
	private TextView txtGiaiBonSo4;
	private TextView txtGiaiNamSo1;
	private TextView txtGiaiNamSo2;
	private TextView txtGiaiNamSo3;
	private TextView txtGiaiNamSo4;
	private TextView txtGiaiNamSo5;
	private TextView txtGiaiNamSo6;
	private TextView txtGiaiSauSo1;
	private TextView txtGiaiSauSo2;
	private TextView txtGiaiSauSo3;
	private TextView txtGiaiBaySo1;
	private TextView txtGiaiBaySo2;
	private TextView txtGiaiBaySo3;
	private TextView txtGiaiBaySo4;
	
	private TextView txtDuoiCua0;
	private TextView txtDuoiCua1;
	private TextView txtDuoiCua2;
	private TextView txtDuoiCua3;
	private TextView txtDuoiCua4;
	private TextView txtDuoiCua5;
	private TextView txtDuoiCua6;
	private TextView txtDuoiCua7;
	private TextView txtDuoiCua8;
	private TextView txtDuoiCua9;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View rootView = null;
		rootView = inflater.inflate(R.layout.fragment_mien_bac, container,
				false);
		return rootView;
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {

		txtMien = (TextView) view.findViewById(R.id.text_title_truyen_thong);
		txtSo1 = (TextView) view.findViewById(R.id.number0);
		txtGiaiNhatSo1 = (TextView) view.findViewById(R.id.number1);
		txtGiaiNhiSo1 = (TextView) view.findViewById(R.id.number2_1);
		txtGiaiNhiSo2 = (TextView) view.findViewById(R.id.number2_2);
		txtGiaiBaSo1 = (TextView) view.findViewById(R.id.number3_1);
		txtGiaiBaSo2 = (TextView) view.findViewById(R.id.number3_2);
		txtGiaiBaSo3 = (TextView) view.findViewById(R.id.number3_3);
		txtGiaiBaSo4 = (TextView) view.findViewById(R.id.number3_4);
		txtGiaiBaSo5 = (TextView) view.findViewById(R.id.number3_5);
		txtGiaiBaSo6 = (TextView) view.findViewById(R.id.number3_6);
		txtGiaiBonSo1 = (TextView) view.findViewById(R.id.number4_1);
		txtGiaiBonSo2 = (TextView) view.findViewById(R.id.number4_2);
		txtGiaiBonSo3 = (TextView) view.findViewById(R.id.number4_3);
		txtGiaiBonSo4 = (TextView) view.findViewById(R.id.number4_4);
		txtGiaiNamSo1 = (TextView) view.findViewById(R.id.number5_1);
		txtGiaiNamSo2 = (TextView) view.findViewById(R.id.number5_2);
		txtGiaiNamSo3 = (TextView) view.findViewById(R.id.number5_3);
		txtGiaiNamSo4 = (TextView) view.findViewById(R.id.number5_4);
		txtGiaiNamSo5 = (TextView) view.findViewById(R.id.number5_5);
		txtGiaiNamSo6 = (TextView) view.findViewById(R.id.number5_6);
		txtGiaiSauSo1 = (TextView) view.findViewById(R.id.number6_1);
		txtGiaiSauSo2 = (TextView) view.findViewById(R.id.number6_2);
		txtGiaiSauSo3 = (TextView) view.findViewById(R.id.number6_3);
		txtGiaiBaySo1 = (TextView) view.findViewById(R.id.number7_1);
		txtGiaiBaySo2 = (TextView) view.findViewById(R.id.number7_2);
		txtGiaiBaySo3 = (TextView) view.findViewById(R.id.number7_3);
		txtGiaiBaySo4 = (TextView) view.findViewById(R.id.number7_4);

		txtDuoiCua0 = (TextView) view.findViewById(R.id.number_loto_number_0);
		txtDuoiCua1 = (TextView) view.findViewById(R.id.number_loto_number_1);
		txtDuoiCua2 = (TextView) view.findViewById(R.id.number_loto_number_2);
		txtDuoiCua3 = (TextView) view.findViewById(R.id.number_loto_number_3);
		txtDuoiCua4 = (TextView) view.findViewById(R.id.number_loto_number_4);
		txtDuoiCua5 = (TextView) view.findViewById(R.id.number_loto_number_5);
		txtDuoiCua6 = (TextView) view.findViewById(R.id.number_loto_number_6);
		txtDuoiCua7 = (TextView) view.findViewById(R.id.number_loto_number_7);
		txtDuoiCua8 = (TextView) view.findViewById(R.id.number_loto_number_8);
		txtDuoiCua9 = (TextView) view.findViewById(R.id.number_loto_number_9);
		
		KQXSMBLoader kQXSMBLoader  = new KQXSMBLoader(); 
		kQXSMBLoader.execute();
		
		super.onViewCreated(view, savedInstanceState);
	}
	
	class KQXSMBLoader extends AsyncTask<Void, Void,KetQuaXoSoMienBac> {

		@Override
		protected void onPreExecute() {
			super.onPreExecute();

		}

		@Override
		protected KetQuaXoSoMienBac doInBackground(Void... params) {
			return JsoupLocal.parseKQXSMB();
		}

		@Override
		protected void onPostExecute(KetQuaXoSoMienBac kq) {
			if (kq != null) {
				txtMien.setText(kq.getTitle());

				txtSo1.setText(kq.getMaSoTrungThuong(0)[0]);
				txtGiaiNhatSo1.setText(kq.getMaSoTrungThuong(1)[1]);
				txtGiaiNhiSo1.setText(kq.getMaSoTrungThuong(2)[2]);
				txtGiaiNhiSo2.setText(kq.getMaSoTrungThuong(2)[3]);
				txtGiaiBaSo1.setText(kq.getMaSoTrungThuong(3)[4]);
				txtGiaiBaSo2.setText(kq.getMaSoTrungThuong(3)[5]);
				txtGiaiBaSo3.setText(kq.getMaSoTrungThuong(3)[6]);
				txtGiaiBaSo4.setText(kq.getMaSoTrungThuong(3)[7]);
				txtGiaiBaSo5.setText(kq.getMaSoTrungThuong(3)[8]);
				txtGiaiBaSo6.setText(kq.getMaSoTrungThuong(3)[9]);
				txtGiaiBonSo1.setText(kq.getMaSoTrungThuong(4)[10]);
				txtGiaiBonSo2.setText(kq.getMaSoTrungThuong(4)[11]);
				txtGiaiBonSo3.setText(kq.getMaSoTrungThuong(4)[12]);
				txtGiaiBonSo4.setText(kq.getMaSoTrungThuong(4)[13]);
				txtGiaiNamSo1.setText(kq.getMaSoTrungThuong(5)[14]);
				txtGiaiNamSo2.setText(kq.getMaSoTrungThuong(5)[15]);
				txtGiaiNamSo3.setText(kq.getMaSoTrungThuong(5)[16]);
				txtGiaiNamSo4.setText(kq.getMaSoTrungThuong(5)[17]);
				txtGiaiNamSo5.setText(kq.getMaSoTrungThuong(5)[18]);
				txtGiaiNamSo6.setText(kq.getMaSoTrungThuong(5)[19]);
				txtGiaiSauSo1.setText(kq.getMaSoTrungThuong(6)[20]);
				txtGiaiSauSo2.setText(kq.getMaSoTrungThuong(6)[21]);
				txtGiaiSauSo3.setText(kq.getMaSoTrungThuong(6)[22]);
				txtGiaiBaySo1.setText(kq.getMaSoTrungThuong(7)[23]);
				txtGiaiBaySo2.setText(kq.getMaSoTrungThuong(7)[24]);
				txtGiaiBaySo3.setText(kq.getMaSoTrungThuong(7)[25]);
				txtGiaiBaySo4.setText(kq.getMaSoTrungThuong(7)[26]);
			
				txtDuoiCua0.setText(kq.getCacSoDauDuoiMaGiai(0));
				txtDuoiCua1.setText(kq.getCacSoDauDuoiMaGiai(1));
				txtDuoiCua2.setText(kq.getCacSoDauDuoiMaGiai(2));
				txtDuoiCua3.setText(kq.getCacSoDauDuoiMaGiai(3));
				txtDuoiCua4.setText(kq.getCacSoDauDuoiMaGiai(4));
				txtDuoiCua5.setText(kq.getCacSoDauDuoiMaGiai(5));
				txtDuoiCua6.setText(kq.getCacSoDauDuoiMaGiai(6));
				txtDuoiCua7.setText(kq.getCacSoDauDuoiMaGiai(7));
				txtDuoiCua8.setText(kq.getCacSoDauDuoiMaGiai(8));
				txtDuoiCua9.setText(kq.getCacSoDauDuoiMaGiai(9));
				

			}
		}

	}

}
